<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>sh</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_001_014_1992">&nbsp;</a>NAME</h4><blockquote>
sh - shell, the standard command language interpreter
</blockquote><h4><a name = "tag_001_014_1993">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

sh <b>[</b>-abCefimnuvx<b>][</b>-o <i>option</i><b>][</b>+abCefmnuvx<b>][</b>+o <i>option</i><b>]
[</b><i>command_file </i><b>[</b><i>argument</i>...<b>]]</b>

sh -c <b>[</b>-abCefimnuvx<b>][</b>-o <i>option</i><b>][</b>+abCefmnuvx<b>][</b>+o <i>option</i><b>]</b><i>command_string
</i><b>[</b><i>command_name </i><b>[</b><i>argument</i>...<b>]]</b>

sh -s<b>[</b>-abCefimnuvx<b>][</b>-o <i>option</i><b>][</b>+abCefmnuvx<b>][</b>+o <i>option</i><b>][</b><i>argument</i><b>]</b>
</code>
</pre>
</blockquote><h4><a name = "tag_001_014_1994">&nbsp;</a>DESCRIPTION</h4><blockquote>
The
<i>sh</i>
utility is a command language interpreter
that executes commands read from
a command-line string, the standard input or a specified file.
The commands to be executed must be
expressed in the language described in
<xref href=shell><a href="chap2.html#tag_001">
Shell Command Language
</a></xref>.
<p>
Pathname expansion will not fail due to the size of a file.
<p>
Shell input and output redirections will have an
implementation-dependent offset maximum that will be established in the
open file description. 
</blockquote><h4><a name = "tag_001_014_1995">&nbsp;</a>OPTIONS</h4><blockquote>
The
<i>sh</i>
utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b>&nbsp;</a> .
<p>
The
<b>-a</b>,
<b>-b</b>,
<b>-C</b>,
<b>-e</b>,
<b>-f</b>,
<b>-m</b>,
<b>-n</b>,
<b>-o</b>&nbsp;<i>option</i>,
<b>-u</b>,
<b>-v</b>
and
<b>-x</b>
options
are described as part of the
<i>set</i>
utility in
<xref href=sbi><a href="chap2.html#tag_001_014">
Special Built-in Utilities
</a></xref>.
The option letters derived from the
<i>set</i>
special built-in are also accepted with a
leading plus sign
(+)
instead of a leading hyphen (meaning the reverse case
of the option as described in this specification).
<p>
The following additional options are supported:
<dl compact>

<dt><b>-c</b>
<dd>Read commands from the
<i>command_string</i>
operand.
Set the value of special parameter
0
(see
<xref href=specpar><a href="chap2.html#tag_001_005_002">
Special Parameters
</a></xref>)
from the value of the
<i>command_name</i>
operand and the positional parameters
($1,
$2,
and so on) in sequence from the remaining
<i>argument</i>
operands.
No commands will be read from the standard input.

<dt><b>-i</b>
<dd>Specify that the shell is
<i>interactive ;</i>
see below.
An implementation may treat specifying the
<b>-i</b>
option as an error if the real user ID
of the calling process does not equal the effective user ID
or if the real group ID does not equal the effective group ID.

<dt><b>-s</b>
<dd>Read commands from the standard input.

</dl>
<p>
If there are no operands and the
<b>-c</b>
option is not specified, the
<b>-s</b>
option is assumed.
<p>
If the
<b>-i</b>
option is present, or if there are no operands and
the shell's standard input and standard error are
attached to a terminal,
the shell is considered to be
<i>interactive .</i>
</blockquote><h4><a name = "tag_001_014_1996">&nbsp;</a>OPERANDS</h4><blockquote>
The following operands are supported:
<dl compact>

<dt><b>-</b><dd>A single hyphen is treated as the first operand and then ignored.
If both "-" and
--
are given as arguments, or if other operands precede the
single hyphen, the results are undefined.

<dt><i>argument</i><dd>
The positional parameters
($1,
$2
and so on)
will be set to
<i>arguments</i>,
if any.

<dt><i>command_file</i><dd>
The pathname of a file containing commands.
If the pathname contains one or more slash characters,
the implementation will attempt to read that file;
the file need not be executable.
If the pathname does not contain a slash character:
<ul>

<li>
The implementation will attempt to read that
file from the current working directory;
the file need not be executable.

<li>
If the file is not in the current working directory,
the implementation may perform a search for an executable file
using the value of
<i>PATH ,
</i>as described in
<xref href=cmdsea><a href="chap2.html#tag_001_009_001_001">
Command Search and Execution
</a></xref>.

</ul>

Special parameter
0
(see
<xref href=specpar><a href="chap2.html#tag_001_005_002">
Special Parameters
</a></xref>)
is set to the value of
<i>command_file</i>.
If
<i>sh</i>
is called using a synopsis form that omits
<i>command_file</i>,
special parameter
0
is set to the value of the first argument passed to
<i>sh</i>
from its parent
(for example,
<i>argv</i>[0]
for a C program),
which is normally
a pathname used to execute the
<i>sh</i>
utility.

<dt><i>command_name</i><dd>
A string assigned to special parameter
0
when executing the commands in
<i>command_string</i>.
If
<i>command_name</i>
is not specified, special parameter
0
is set to the value of the first argument passed to
<i>sh</i>
from its parent
(for example,
<i>argv</i>[0]
for a C program),
which is normally a pathname used to execute the
<i>sh</i>
utility.

<dt><i>command_string</i><dd>
A string that is interpreted by the shell
as one or more commands, as if the string were the argument to the <b>XSH</b> specification
<i><a href="../xsh/system.html">system()</a></i>
function.
If the
<i>command_string</i>
operand is an empty string,
<i>sh</i>
will exit with a zero exit status.

</dl>
</blockquote><h4><a name = "tag_001_014_1997">&nbsp;</a>STDIN</h4><blockquote>
The standard input will be used only if one of the following is true:
<ul>
<p>
<li>
The
<b>-s</b>
option is specified.
<p>
<li>
The
<b>-c</b>
option is not specified and no operands are specified.
<p>
<li>
The script executes one or more commands that require
input from standard input (such as a
<i><a href="read.html">read</a></i>
command that does not redirect its input).
<p>
</ul>
<p>
See the INPUT FILES section.
<p>
When the shell is using standard input and it invokes a
command that also uses standard input, the shell
ensures that the standard input file pointer points
directly after the command it has read when the command
begins execution.
It will not read ahead in such a manner that any characters
intended to be read by the invoked command are consumed by the
shell (whether interpreted by the shell or not) or that characters
that are not read by the invoked command are not seen by the shell.
When the command expecting to read standard input
is started asynchronously by an interactive shell,
it is unspecified whether characters are read by the
command or interpreted by the shell.
<p>
If the standard input to
<i>sh</i>
is a FIFO or terminal device and
is set to non-blocking reads, then
<i>sh</i>
will enable blocking reads on standard input.
This will remain in effect when the command completes.
(This concerns an instance of
<i>sh</i>
that has been invoked, probably by a C-language program,
with standard input that has been opened using the
O_NONBLOCK flag; see
<i><a href="../xsh/open.html">open()</a></i>
in the <b>XSH</b> specification.
If the shell did not reset this flag, it would immediately
terminate because no input data would be available yet
and that would be considered the same as end-of-file.)
</blockquote><h4><a name = "tag_001_014_1998">&nbsp;</a>INPUT FILES</h4><blockquote>
The input file must be a text file,
except that line lengths are unlimited.
If the input file is empty or consists solely of
blank lines or comments, or both,
<i>sh</i>
will exit with a zero exit status.
<br>
</blockquote><h4><a name = "tag_001_014_1999">&nbsp;</a>ENVIRONMENT VARIABLES</h4><blockquote>
The following environment variables affect the execution of
<i>sh</i>:
<dl compact>

<dt><i>FCEDIT</i><dd>
This variable, when expanded by the shell,
determines the default value for the
<b>-e</b>&nbsp;<i>editor</i>
option's
<i>editor</i>
option-argument.
If
<i>FCEDIT</i>
is null or unset,
<i><a href="ed.html">ed</a></i>
will be used as the editor.

<dt><i>HISTFILE</i><dd>
Determine a pathname naming a command history file.
If the
<i>HISTFILE</i>
variable is not set, the
shell may attempt to access or create a file
<b>.sh_history</b>
in the user's home directory.
If the shell cannot
obtain both read and write access to,
or create, the history file, it
will use an unspecified mechanism that allows the history
to operate properly.
(References to history &quot;file&quot; in this section
are understood to mean this unspecified mechanism
in such cases.)
An implementation may choose to access this variable only when
initialising the history file;
this initialisation will occur when
<i><a href="fc.html">fc</a></i>
or
<i>sh</i>
first attempt to retrieve entries from,
or add entries to, the file, as the result of
commands issued by the user, the file named by the
<i>ENV</i>
variable, or implementation-dependent system startup files.
(The initialisation process for the history file
can be dependent on the system startup files, in that
they may contain commands that will effectively
preempt the user's settings of
<i>HISTFILE</i>
and
<i>HISTSIZE .
</i>For example, function definition commands are recorded
in the history file, unless the
<i>set</i>
<b>-o</b>
nolog
option is set.
If the system administrator includes function definitions
in some system startup file called before the
<i>ENV</i>
file, the history file will be initialised before
the user gets a chance to influence its characteristics.)
In some historical shells, the history file is initialised
just after the
<i>ENV</i>
file has been processed.
Therefore, it is implementation-dependent whether changes made to
<i>HISTFILE</i>
after the history file has been initialised are effective.
Implementations may choose to disable the history list
mechanism for users with appropriate privileges who do not set
<i>HISTFILE ;
</i>the specific circumstances under which this will occur are
implementation-dependent.
If more than one instance of the shell is using the same history
file, it is unspecified how updates to the history file from
those shells interact.
As entries are deleted from the history file,
they will be deleted oldest first.
It is unspecified when history file entries are
physically removed from the history file.

<dt><i>HISTSIZE</i><dd>
Determine a decimal number representing
the limit to the number of previous commands that are accessible.
If this variable is unset,
an unspecified default greater than or equal to 128 will be used.
The maximum number of commands in the history list is unspecified,
but will be at least 128.
An implementation may choose to access this variable only when
initialising the history file,
as described under
<i>HISTFILE .
</i>Therefore, it is unspecified whether changes made to
<i>HISTSIZE</i>
after the history file has been initialised are effective.

<dt><i>HOME</i><dd>Determine the
pathname of the user's home directory.
The contents of
<i>HOME</i>
are used in Tilde Expansion as described in
<xref href=tildexp><a href="chap2.html#tag_001_006_001">
Tilde Expansion
</a></xref>.

<dt><i>IFS</i><dd><i>Input field separators :</i>
a string treated as a list of characters
that is used for field splitting and to
split lines into words with the
<i><a href="read.html">read</a></i>
command.
See
<xref href=fldspl><a href="chap2.html#tag_001_006_005">
Field Splitting
</a></xref>.
If
<i>IFS</i>
is not set, the shell behaves as if the value of
<i>IFS</i>
were the
space,
tab
and
newline
characters.
Implementations may ignore the value of
<i>IFS</i>
in the environment at the time
<i>sh</i>
is invoked, treating
<i>IFS</i>
as if it were not set.

<dt><i>LANG</i><dd>Provide a default value for the internationalisation variables
that are unset or null.
If
<i>LANG</i>
is unset or null, the corresponding value from the
implementation-dependent default locale will be used.
If any of the internationalisation variables contains an invalid setting, the
utility will behave as if none of the variables had been defined.

<dt><i>LC_ALL</i><dd>
If set to a non-empty string value,
override the values of all the other internationalisation variables.

<dt><i>LC_COLLATE</i><dd>
Determine the behaviour of range
expressions, equivalence classes and multi-character collating elements
within pattern matching.

<dt><i>LC_CTYPE</i><dd>
Determine the
locale for the interpretation of sequences of bytes of text data
as characters (for example, single-
versus multi-byte characters in arguments and input files),
which characters are defined as
letters (character class
<b>alpha</b>),
and the behaviour of character classes within pattern matching.

<dt><i>LC_MESSAGES</i><dd>
Determine the locale that should be used to affect
the format and contents of diagnostic
messages written to standard error.

<dt><i>MAIL</i><dd>Determine a pathname of the user's mailbox file
for purposes of incoming mail notification.
If this variable is set,
the shell will inform the user if the file named
by the variable is created or if its modification time has changed.
Informing the user is accomplished by writing a string
of unspecified format
to standard error prior to the writing of
the next primary prompt string
after the completion of an interval defined by the
<i>MAILCHECK</i>
variable.
The user will be informed only if
<i>MAIL</i>
is set and
<i>MAILPATH</i>
is not set.

<dt><i>MAILCHECK</i><dd>
Establish a decimal integer
value that specifies how often (in seconds) the shell
will check for the arrival of mail in the files specified by the
<i>MAILPATH</i>
or
<i>MAIL</i>
variables.
The default value is 600 seconds.
If set to zero, the shell will check before issuing each primary prompt.

<dt><i>MAILPATH</i><dd>
Provide a list of pathnames
and optional messages separated by colons.
If this variable is set, the shell will inform
the user if any of the files named by the variable are created or
if any of their modification times change.
(See the preceding entry for
<i>MAIL</i>
for descriptions of mail arrival and user informing.)
Each pathname can be followed by
"%"
and a string that will be
subjected to parameter expansion and
written to standard error when the
modification time changes.
If a
"%"
character in the pathname is preceded by a backslash,
it will be treated as a literal
"%"
in the pathname.
The default message is unspecified.

The
<i>MAILPATH</i>
environment variable takes precedence over the
<i>MAIL</i>
variable.

<dt><i>NLSPATH</i><dd>
Determine the location of message catalogues
for the processing of
<i>LC_MESSAGES .
</i>
<dt><i>PATH</i><dd>Establish a string formatted as described in
the <b>XBD</b> specification, <a href="../xbd/envvar.html"><b>Environment Variables</b>&nbsp;</a> ,
used to effect command interpretation.
See
<xref href=cmdsea><a href="chap2.html#tag_001_009_001_001">
Command Search and Execution
</a></xref>.

</dl>
</blockquote><h4><a name = "tag_001_014_2000">&nbsp;</a>ASYNCHRONOUS EVENTS</h4><blockquote>
Default.
</blockquote><h4><a name = "tag_001_014_2001">&nbsp;</a>STDOUT</h4><blockquote>
See the STDERR section.
<br>
</blockquote><h4><a name = "tag_001_014_2002">&nbsp;</a>STDERR</h4><blockquote>
Except as otherwise stated (by the descriptions of any
invoked utilities or in interactive mode),
standard error is
used only for diagnostic messages.
</blockquote><h4><a name = "tag_001_014_2003">&nbsp;</a>OUTPUT FILES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_2004">&nbsp;</a>EXTENDED DESCRIPTION</h4><blockquote>
See
<xref href=shell><a href="chap2.html#tag_001">
Shell Command Language
</a></xref>.
The following additional capabilities are supported.
<h5><a name = "tag_001_014_2004_001">&nbsp;</a>Command History List</h5>
<xref type="5" name="shcmdhist"></xref>
When the
<i>sh</i>
utility is being used interactively,
it maintains a list of commands previously entered
from the terminal
in the file named by the
<i>HISTFILE</i>
environment variable.
The type, size and internal format of this file are unspecified.
Multiple
<i>sh</i>
processes can share access to the file for a user,
if file access permissions allow this;
see the description of the
<i>HISTFILE</i>
environment variable.
<h5><a name = "tag_001_014_2004_002">&nbsp;</a>Command Line Editing</h5>
When
<i>sh</i>
is being used interactively from a terminal, the current
command and the command history (see
<i><a href="fc.html">fc</a></i>)
can be edited using
<i>vi-mode</i>
command line editing.
This mode uses commands, described below,
similar to a subset of those described in the
<i><a href="vi.html">vi</a></i>
utility.
Implementations may offer other command line editing modes
corresponding to other editing utilities.
<p>
The command
<i>set</i>
<b>-o</b>
<b>v</b>
enables vi-mode editing and places
<i>sh</i>
into
<i><a href="vi.html">vi</a></i>
insert mode (see
<xref href=shvicle><a href="#tag_001_014_2004_003">
Command Line Editing (vi-mode)
</a></xref>).
This command also disables any other
editing mode that the implementation may provide.
The command
<i>set</i>
<b>+o</b>
<b>v</b>
disables vi-mode editing.
<p>
Certain block-mode terminals may be unable to support shell command
line editing.
If a terminal is unable to provide either edit mode,
it need not be possible to
<i>set</i>
<b>-o</b>
<b>v</b>
when using the shell on this terminal.
<p>
In the following sections, the characters
erase,
interrupt,
kill
and
end-of-file
are those set by the
<i><a href="stty.html">stty</a></i>
utility.
<h5><a name = "tag_001_014_2004_003">&nbsp;</a>Command Line Editing (vi-mode)</h5>
<xref type="5" name="shvicle"></xref>
With vi-mode enabled,
<i>sh</i>
can be switched between insert mode and command mode.
<p>
When in insert mode, an entered character
will be inserted into the command line,
except as noted in
<xref href=shvieim><a href="#tag_001_014_2004_004">
vi Line Editing Insert Mode
</a></xref>.
Upon entering
<i>sh</i>
and after termination of the previous command,
<i>sh</i>
will be in insert mode.
<p>
Typing an escape character wll switch
<i>sh</i>
into command mode (see
<xref href=shviecm><a href="#tag_001_014_2004_005">
vi Line Editing Command Mode
</a></xref>).
In command mode, an entered character will either invoke a defined
operation, be used as part of a multi-character operation
or be treated as an error.
A character that is not recognised as part of an editing
command will terminate any specific editing command and
will alert the terminal.
Typing the
<i>interrupt</i>
character in command mode will cause
<i>sh</i>
to terminate command line editing on the
current command line, reissue the
prompt on the next line of the terminal
and reset the command history (see
<i><a href="fc.html">fc</a></i>)
so that the most recently executed command
is the previous command (that is, the
command that was being edited when it was
interrupted is not reentered into the history).
<p>
In the following sections, the phrase &quot;move the cursor to the
beginning of the word&quot; means &quot;move the cursor to the first
character of the current word&quot; and the phrase &quot;move the cursor to the
end of the word&quot; means &quot;move the cursor to the last
character of the current word&quot;.
The phrase &quot;beginning of the command line&quot; indicates
the point between the end of the prompt string issued by the shell
(or the beginning of the terminal line, if there is no prompt string)
and the first character of the command text.
<h5><a name = "tag_001_014_2004_004">&nbsp;</a>vi Line Editing Insert Mode</h5>
<xref type="5" name="shvieim"></xref>
While in insert mode, any character typed will be inserted in the
current command line, unless it is from the following set.
<dl compact>

<dt>newline<dd>
Execute the current command line being edited.

<dt><i>erase</i><dd>Delete the character previous to the current cursor position
and move the current cursor position back one character.
In insert mode, characters will be erased from both the screen and
the buffer when backspacing.

<dt><i>interrupt</i><dd>
Terminate command line editing with the same effects
as described for interrupting command mode; see
<xref href=shvicle><a href="#tag_001_014_2004_003">
Command Line Editing (vi-mode)
</a></xref>.

<dt><i>kill</i><dd>Clear all the characters from the input line.

<dt>&lt;control&gt;-V<dd>
Insert the next character input, even if the character
is otherwise a special insert mode character.

<dt>&lt;control&gt;-W<dd>
Delete the characters from the one preceding the cursor to
the preceding word boundary.
The word boundary in this case
is the closer to the cursor of
either the beginning of the line or a character that is
in neither the
<b>blank</b>
nor
<b>punct</b>
character classification of the current locale.

<dt><b>\</b><dd>On some systems, when a backslash is followed by an
<i>erase</i>
or
<i>kill</i>
character, that character will be inserted into the input line.
This is not actually a feature of
<i>sh</i>
command line editing insert mode, but one of
terminal line drivers when the
<i><a href="stty.html">stty</a></i>
<b>iexten</b>
flag is set.
Otherwise, the backslash itself will be inserted into the input line.

<dt><i>end-of-file</i><dd>

Interpreted as the end of input in
<i>sh</i>.
This interpretation will occur only at the beginning of an input line.
If end-of-file is entered other than at the beginning of the line,
the results are unspecified.

<dt>&lt;ESC&gt;<dd>Place
<i>sh</i>
into command mode.

</dl>
<h5><a name = "tag_001_014_2004_005">&nbsp;</a>vi Line Editing Command Mode</h5>
<xref type="5" name="shviecm"></xref>
In command mode for the command line editing feature, decimal
digits not beginning with 0 that precede a command letter will be remembered.
Some commands use these decimal digits as a count number
that affects the operation.
<p>
The term
<i>motion command</i>
represents one of the commands:
<pre>
<code>
&lt;space&gt;  0  b  F  l  W  ^  $  ;  E  f  T  w  |  ,  B  e  h  t
</code>
</pre>
<p>
Any command that modifies the current line will cause a copy of the
current line to be made at the end of the
command history, the current
line will become that copy,
and the edit will be performed on that copy.
<p>
Any command that is preceded by
<i>count</i>
will take a count (the numeric
value of any preceding decimal digits).
Unless otherwise noted, this
count will cause the specified operation to repeat by the number of
times specified by the count.
Also unless otherwise noted, a
<i>count</i>
that is out of range is considered an error condition and
will alert the terminal,
but neither the cursor position,
nor the command line, will change.
<p>
The terms
<i>word</i>
and
<i>bigword</i>
are used as defined in the
<i><a href="vi.html">vi</a></i>
description.
The term
<i>save buffer</i>
corresponds to the term
<i>unnamed buffer</i>
in
<i><a href="vi.html">vi</a></i>.
<p>
The following commands are recognised in command mode:
<dl compact>

<dt>newline<dd>
Execute the current command line being edited.

<dt>&lt;control&gt;-L<dd>
Redraw the current command line.
Position the cursor at the same location on the new command line.

<dt><b>#</b><dd>Insert the character # at the beginning of the
current command line and
treat the current command line as a comment.
This line will be entered into the command history; see
<i><a href="fc.html">fc</a></i>.

<dt><b>=</b><dd>Display the possible shell word expansions (see
<xref href=wordexp><a href="chap2.html#tag_001_006">
Word Expansions
</a></xref>)
of the bigword at the current command line position.
These expansions will be displayed on subsequent terminal lines.
If the bigword contains none of the characters "?", "*" or "[",
an asterisk
(*)
will be implicitly assumed at the end.
If any directories are matched, these expansions
will have a "/" character appended.
After the expansion, the
line will be redrawn, the cursor will be repositioned
at the current cursor position,
and
<i>sh</i>
will be placed in
command mode.

<dt><b>\</b><dd>Perform pathname expansion (see
<xref href=pathexp><a href="chap2.html#tag_001_006_006">
Pathname Expansion
</a></xref>)
on the current bigword, up
to the largest set of characters that can be matched uniquely.
If the bigword contains none
of the characters "?", "*" or "[",
an asterisk
(*)
will be implicitly assumed at the end.
This maximal expansion then
will replace the original bigword in the command line, and the cursor
will be placed after this expansion.
If the resulting bigword completely and uniquely
matches a directory,
a "/" character will be inserted directly after the bigword.
If some other file is completely matched, a single space
character will be inserted after the bigword.
After this operation,
<i>sh</i>
will be placed in insert mode.

<dt><b>*</b><dd>Perform pathname expansion on the current bigword and insert all
expansions into the command to replace the current
bigword, with each expansion separated by a single
space
character.
If at the end of the line, the current cursor position will be moved to
the first column position following the expansions and
<i>sh</i>
will be placed in insert mode.
Otherwise, the current cursor position will be
the last column position of the first character after the expansions and
<i>sh</i>
will be placed in insert mode.
If the current bigword contains none of the characters "?", "*" or "[",
before the operation, an asterisk will be implicitly assumed at the end.

<dt><b>@</b><i>letter</i><dd>
Insert the value of the alias named
_<i>letter</i>
The symbol
<i>letter</i>
represents a single alphabetic character from the
portable character set; implementations may support
additional characters as an extension.
If the alias
_<i>letter</i>
contains other editing commands,
these commands will be
performed as part of the insertion.
If no alias
_<i>letter</i>
is enabled, this command will have no effect.

<dt><b>[</b><i>count</i><b>]~</b><dd>
Convert, if the current character is a lower-case letter,
to the equivalent upper-case letter and
<i>vice</i>versa<i>,</i>
as prescribed by the current locale.
The current cursor position then will be advanced by one character.
If the cursor was positioned on the last character of the line,
the case conversion will occur, but the cursor will not advance.
If the
~
command is preceded by a
<i>count</i>,
that number of characters will be converted,
and the cursor will be advanced to
the character position after the last character
converted.
If the
<i>count</i>
is larger than the number of characters after the cursor,
this is not considered an error;
the cursor will advance to the last character on the line.

<dt><b>[</b><i>count</i><b>].</b><dd>
Repeat the most recent non-motion command, even if it was executed on
an earlier command line.
If the previous command was
preceded by a
<i>count</i>,
and no count is given on the "." command,
the count from the previous command
will be included as part of the repeated command.
If the "." command is preceded by a
<i>count</i>,
this will override any
<i>count</i>
argument to the previous command.
The
<i>count</i>
specified in the "." command will become the count for
subsequent "." commands issued without a count.

<dt><b>[</b><i>number</i><b>]v</b><dd>
Invoke the
<i><a href="vi.html">vi</a></i>
editor to edit the current command line in a temporary file.
When the editor exits, the
commands in the temporary file will be executed.
If a
<i>number</i>
is prefixed to the command, it specifies the command
number in the
command history to be edited, rather than the
current command line.

<dt><b>[</b><i>count</i><b>]l</b><dd>
<dt><b>[</b><i>count</i><b>]</b>&lt;space&gt;<dd>
Move the current cursor position to the next character position.
If the cursor was positioned on the last character of the line,
the terminal will be alerted
and the cursor will not be advanced.
If the
<i>count</i>
is larger than the number of characters after the cursor,
this is not considered an error;
the cursor will advance to the last character on the line.

<dt><b>[</b><i>count</i><b>]h</b><dd>
Move the current cursor position to the
<i>count</i>th
(default 1) previous character position.
If the cursor was positioned on the first character
of the line,
the terminal will be alerted
and the cursor will not be moved.
If the count is
larger than the number of characters before the cursor, this
is not considered an error; the cursor will move to the
first character on the line.

<dt><b>[</b><i>count</i><b>]w</b><dd>
Move to the start of the next word.
If the cursor was positioned on the last character of the line,
the terminal will be alerted
and the cursor will not be advanced.
If the
<i>count</i>
is larger than the number of words after the cursor,
this is not considered an error;
the cursor will advance to the last character on the line.

<dt><b>[</b><i>count</i><b>]W</b><dd>
Move to the start of the next bigword.
If the cursor was positioned on the last character of the line,
the terminal will be alerted
and the cursor will not be advanced.
If the
<i>count</i>
is larger than the number of bigwords after the cursor,
this is not considered an error;
the cursor will advance to the last character on the line.

<dt><b>[</b><i>count</i><b>]e</b><dd>
Move to the end of the current word.
If at the end of a word, move to the end of the next word.
If the cursor was positioned on the last character of the line,
the terminal will be alerted
and the cursor will not be advanced.
If the
<i>count</i>
is larger than the number of words after the cursor,
this is not considered an error;
the cursor will advance to the last character on the line.

<dt><b>[</b><i>count</i><b>]E</b><dd>
Move to the end of the current bigword.
If at the end of a bigword, move to the end of the next bigword.
If the cursor was positioned on the last character of the line,
the terminal will be alerted
and the cursor will not be advanced.
If the
<i>count</i>
is larger than the number of bigwords after the cursor,
this is not considered an error;
the cursor will advance to the last character on the line.

<dt><b>[</b><i>count</i><b>]b</b><dd>
Move to the beginning of the current word.
If at the beginning of a word, move to the beginning of the previous word.
If the cursor was positioned on the first character of the line,
the terminal will be alerted
and the cursor will not be moved.
If the
<i>count</i>
is larger than the number of words
preceding the cursor,
this is not considered an error;
the cursor will return to the first character on the line.

<dt><b>[</b><i>count</i><b>]B</b><dd>
Move to the beginning of the current bigword.
If at the beginning
of a bigword, move to the beginning of the previous bigword.
If the cursor was positioned on the first character of the line,
the terminal will be alerted
and the cursor will not be moved.
If the
<i>count</i>
is larger than the number of bigwords preceding the cursor,
this is not considered an error;
the cursor will return to the first character on the line.

<dt><b>^</b><dd>Move the current cursor position to the first character on the
input line that is not a
blank character.

<dt><b>$</b><dd>Move to the last character position on the current command line.

<dt><b>0</b><dd>(Zero.)
Move to the first character position on the current command line.

<dt><b>[</b><i>count</i><b>]\||</b><dd>
Move to the
<i>count</i>th
character position on the current command line.
If no number is specified, move to the first position.
The first character position is numbered 1.
If the count is larger than the number of characters on
the line, this is not considered an error; the
cursor will be placed on the last character on the line.

<dt><b>[</b><i>count</i><b>]f</b><i>c</i><dd>
Move to the first occurrence of the character
<i>c</i>
that occurs after the current cursor position.
If the cursor was positioned on the last character of the line,
the terminal will be alerted
and the cursor will not be advanced.
If the character
<i>c</i>
does not occur in the line after the
current cursor position,
the terminal will be alerted
and the cursor will not be moved.

<dt><b>[</b><i>count</i><b>]F</b><i>c</i><dd>
Move to the first occurrence of the character
<i>c</i>
that occurs before the current cursor position.
If the cursor was positioned on the first character of the line,
the terminal will be alerted
and the cursor will not be moved.
If the character
<i>c</i>
does not occur in the line before the
current cursor position,
the terminal will be alerted
and the cursor will not be moved.

<dt><b>[</b><i>count</i><b>]t</b><i>c</i><dd>
Move to the character before the first
occurrence of the character
<i>c</i>
that occurs after the
current cursor position.
If the cursor was positioned
on the last character of the line,
the terminal will be alerted
and the cursor will not be advanced.
If the character
<i>c</i>
does not occur in the line after the current cursor position,
the terminal will be alerted
and the cursor will not be moved.

<dt><b>[</b><i>count</i><b>]T</b><i>c</i><dd>
Move to the character after the first
occurrence of the character
<i>c</i>
that occurs before the
current cursor position.
If the cursor was positioned
on the first character of the line,
the terminal will be alerted
and the cursor will not be moved.
If the character
<i>c</i>
does not occur in the line before the current cursor position,
the terminal will be alerted
and the cursor will not be moved.

<dt><b>[</b><i>count</i><b>];</b><dd>
Repeat the most recent
<b>f</b>,
<b>F</b>,
<b>t</b>
or
<b>T</b>
command.
Any number argument
on that previous command will be ignored.
Errors are those described for the repeated command.

<dt><b>[</b><i>count</i><b>],</b><dd>
Repeat the most recent
f,
F,
t
or
T
command.
Any number argument
on that previous command will be ignored.
However, reverse the direction
of that command.

<dt><b>a</b><dd>Enter insert mode after the current cursor position.
Characters that are entered will be inserted before the next character.

<dt><b>A</b><dd>Enter insert mode after the end of the current command line.

<dt><b>i</b><dd>Enter insert mode at the current cursor position.
Characters
that are entered will be inserted before the current character.

<dt><b>I</b><dd>Enter insert mode at the beginning of the current command line.

<dt><b>R</b><dd>Enter insert mode, replacing characters from the
command line beginning at the current cursor position.

<dt><b>[</b><i>count</i><b>]c</b><i>motion</i><dd>
Delete the characters between the current cursor position and the
cursor position that would result from the specified
<i>motion</i>
command.
Then enter insert mode before
the first character following any deleted characters.
If
<i>count</i>
is specified, it will be applied to the
motion command.
A
<i>count</i>
will be ignored for the following motion commands:
<pre>
<code>
0    ^    $    c
</code>
</pre>

If the
<i>motion</i>
command
is the character
<b>c</b>,
the current command line will be cleared and
insert mode will be entered.
If the
<i>motion</i>
command would move
the current cursor position toward the beginning of the command line,
the character under the
current cursor position will not be deleted.
If the motion command would move the current cursor position
toward the end of the command line, the character under the
current cursor position will be deleted.
If the
<i>count</i>
is larger than the number of characters
between the current cursor position and the end of the
command line toward which the motion command would move
the cursor, this is not considered an error; all
of the remaining characters in the aforementioned range
will be deleted and insert mode will be entered.
If the motion command is invalid,
the terminal will be alerted,
the cursor
will not be moved, and no text will be deleted.

<dt><b>C</b><dd>Delete from the current character to the end of the line and
enter insert mode at the new end-of-line.

<dt><b>S</b><dd>Clear the entire current command line and enter insert mode.

<dt><b>[</b><i>count</i><b>]r</b><i>c</i><dd>
Replace the current character with the character
<i>c</i>.
With a number
<i>count</i>,
replace the current and the following
<i>count</i>-1
characters.
After this command, the current cursor position will be
on the last character that was changed.
If the
<i>count</i>
is larger than the number of characters after the cursor,
this is not considered an error;
all of the remaining characters will be changed.

<dt><b>[</b><i>count</i><b>]_</b><dd>
Append a
space character
after the current character position and then
append the last bigword in the previous input line after the
space character.
Then enter insert mode after the last character just appended.
With a number
<i>count</i>,
append the
<i>count</i>th
bigword in the previous line.

<dt><b>[</b><i>count</i><b>]x</b><dd>
Delete the character at the current cursor position
and place the deleted characters in the save buffer.
If the cursor was positioned on the last character of the line,
the character will be deleted and the cursor position
will be moved to the previous character (the new last character).
If the
<i>count</i>
is larger than the number of characters after the cursor,
this is not considered an error;
all the characters from the cursor to the end of the line will be deleted.

<dt><b>[</b><i>count</i><b>]X</b><dd>
Delete the character before the current cursor position
and place the deleted characters in the save buffer.
The character under the current cursor position
will not change.
If the cursor was positioned on the first character of the line,
the terminal will be alerted,
and the
<b>X</b>
command will have no effect.
If the line contained a single character, the
<b>X</b>
command will have no effect.
If the line contained no characters,
the terminal will be alerted
and the cursor will not be moved.
If the
<i>count</i>
is larger than the number of characters before the cursor,
this is not considered an error;
all the characters from before the cursor to the beginning
of the line will be deleted.

<dt><b>[</b><i>count</i><b>]d</b><i>motion</i><dd>
Delete the characters between the current cursor position and the
character position that would result from the
<i>motion</i>
command.
A number
<i>count</i>
repeats the
<i>motion</i>
command
<i>count</i>
times.
If the motion
command would move toward the beginning of the command line,
the character under the current cursor position
will not be deleted.
If the motion command is
<b>d</b>,
the entire current command line will be cleared.
If the
<i>count</i>
is larger than the number of characters
between the current cursor position and the end of the
command line toward which the motion command would move
the cursor, this is not considered an error; all
of the remaining characters in the aforementioned range
will be deleted.
The deleted characters will be placed in the save buffer.

<dt><b>D</b><dd>Delete all characters from the current cursor position
to the end of the line.
The deleted characters will be placed in the save buffer.

<dt><b>[</b><i>count</i><b>]y</b><i>motion</i><dd>
Yank (that is, copy) the characters from the current cursor position to the
position resulting from the
<i>motion</i>
command into a
save buffer.
A number
<i>count</i>
will be applied to the
<i>motion</i>
command.
If the motion
command would move toward the beginning of the command line,
the character under the current cursor position
will not be included in the set of yanked characters.
If the motion command is
<b>y</b>,
the entire current command line will be yanked into the save buffer.
The current cursor position will be unchanged.
If the
<i>count</i>
is larger than the number of characters
between the current cursor position and the end of the
command line toward which the motion command would move
the cursor, this is not considered an error; all
of the remaining characters in the aforementioned range
will be yanked.

<dt><b>Y</b><dd>Yank the characters from the current cursor position to the
end of the line into the save buffer.
The current character position will be unchanged.

<dt><b>[</b><i>count</i><b>]p</b><dd>
Put a copy of the current contents of the save buffer
after the current cursor position.
The current cursor position will be
advanced to the last character put from the save buffer.
A
<i>count</i>
indicates how many copies of the save buffer will be put.

<dt><b>[</b><i>count</i><b>]P</b><dd>
Put a copy of the current contents of the save buffer
before the current cursor position.
The current cursor position will be
moved to the last character put from the save buffer.
A
<i>count</i>
indicates how many copies of the save buffer will be put.

<dt><b>u</b><dd>Undo the last command that modified the text of the current command line.

<dt><b>U</b><dd>Undo all changes made to the current command line since first entering
command mode on the line.

<dt><b>[</b><i>count</i><b>]k</b><dd>
<dt><b>[</b><i>count</i><b>]-</b><dd>
Replace the current command line with the previous command line
in the shell command history.
The cursor will be positioned on the first character of the new command.
A count preceding the command
will have the same effect as executing the command
<i>count</i>
times.
If a
<b>k</b>
or "-"
command retreats past the maximum number of commands
in effect for this shell (affected by the
<i>HISTSIZE</i>
environment variable),
the terminal will be alerted
and the command will have no effect.

<dt><b>[</b><i>count</i><b>]j</b><dd>
<dt><b>[</b><i>count</i><b>]+</b><dd>
Replace the current command line with the next command line
in the shell command history.
The cursor will be positioned on the first character of the new command.
The command history position will be remembered, and any
<b>k</b>
or "-" command, or
<b>j</b>
or + command, will decrement or increment that
position and then will fetch the line at the new position.
If a
<b>j</b>
or
command advances past the most recent line in
the history, the current command line will be restored to the contents
before the first
<b>k</b>
or "-".


<dt><b>[</b><i>number</i><b>]G</b><dd>
Replace the current command line with the contents of the oldest
command line stored in the shell command history.
With a number
<i>number</i>,
replace the current command line with the contents of command
<i>number</i>
in the history.

<dt><b>/</b><i>string</i>&lt;newline&gt;<dd>
Move backward through the command history, searching
for the specified
<i>string</i>,
beginning with the previous command line.
If it is not found, the current command line will be unchanged.
If it is found in a previous line, this command
will behave equivalently to a set of
<b>k</b>
commands to reach that line.
If
<i>string</i>
begins with "^", the characters after the "^"
will be matched only at the beginning of a line.

<dt><b>?</b><i>string</i>&lt;newline&gt;<dd>
Move forward through the command history, searching for the specified string.
If it is
not found, the current command line will be unchanged.
If the string
is found in the current command line, the current cursor position will be
moved to the beginning of that string.
If it is found in the
history, this command will behave equivalently to a set of
<b>j</b>
commands to reach that line.
If
<i>string</i>
begins with "^",
the characters after the "^" will be matched only at the
beginning of a line.

<dt><b>n</b><dd>Repeat the most recent <b>/</b> or <b>?</b> command.

<dt><b>N</b><dd>Repeat the most recent <b>/</b> or <b>?</b> command, reversing the direction
of the search.

</dl>
</blockquote><h4><a name = "tag_001_014_2005">&nbsp;</a>EXIT STATUS</h4><blockquote>
The following exit values are returned:
<dl compact>

<dt>0<dd>The script to be executed consisted solely
of zero or more blank lines or comments, or both.

<dt>1-125<dd>A non-interactive shell detected a syntax,
redirection or variable assignment error.

<dt>127<dd>A specified
<i>command_file</i>
could not be found by a non-interactive shell.

</dl>
<p>
Otherwise, the shell will return the exit status of
the last command it invoked or attempted to invoke (see also the
<i><a href="chap2.html#tag_001_014_007">exit</a></i>
utility in
<xref href=sbi><a href="chap2.html#tag_001_014">
Special Built-in Utilities
</a></xref>).
</blockquote><h4><a name = "tag_001_014_2006">&nbsp;</a>CONSEQUENCES OF ERRORS</h4><blockquote>
See
<xref href=sherr><a href="chap2.html#tag_001_008_001">
Consequences of Shell Errors
</a></xref>.
</blockquote><h4><a name = "tag_001_014_2007">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
Standard input and standard error are the files that
determine whether a shell is interactive when
<b>-i</b>
is not specified.
For example:
<pre>
<code>
sh &gt; file
</code>
</pre>
and:
<pre>
<code>
sh 2&gt; file
</code>
</pre>
create interactive and non-interactive shells, respectively.
Although both accept terminal input, the results of
error conditions are different, as described in
<xref href=sherr><a href="chap2.html#tag_001_008_001">
Consequences of Shell Errors
</a></xref>;
in the second example a redirection error encountered by a
special built-in utility will abort the shell.
<p>
On systems that support set-user-ID scripts,
a historical trapdoor has been to link a script to the name
<b>-i</b>.
When it is called by a sequence such as:
<pre>
<code>
sh -
</code>
</pre>
or by:
<pre>
<code>
#!&nbsp;/bin/sh&nbsp;-
</code>
</pre>
the historical systems have assumed that no option letters follow.
Thus, this specification allows the single hyphen to mark
the end of the options, in addition to the use of the regular
--
argument, because the older practice is so pervasive.
<p>
A portable application must protect its first operand,
if it starts with a plus sign,
by preceding it with the --
argument that denotes the end of the options.
<br>
</blockquote><h4><a name = "tag_001_014_2008">&nbsp;</a>EXAMPLES</h4><blockquote>
<ol>
<p>
<li>
Execute a shell command from a string:
<pre>
<code>
sh -c "cat myfile"
</code>
</pre>
<p>
<li>
Execute a shell script from a file in the current directory:
<pre>
<code>
sh my_shell_cmds
</code>
</pre>
<p>
</ol>
</blockquote><h4><a name = "tag_001_014_2009">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
The IEEE PASC 1003.2 Interpretations Committee has forwarded concerns about
parts of this interface definition to the IEEE PASC Shell and Utilities Working Group
which is identifying the corrections.
A future revision of this specification will align with
IEEE Std. 1003.2b when finalised.
</blockquote><h4><a name = "tag_001_014_2010">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="cd.html">cd</a></i>,
<i><a href="echo.html">echo</a></i>,
<i><a href="pwd.html">pwd</a></i>,
<i><a href="test.html">test</a></i>,
<i><a href="umask.html">umask</a></i>,
the <b>XSH</b> specification description of
<i><a href="../xsh/dup.html">dup()</a></i>,
<i>exec ,</i>
<i><a href="../xsh/exit.html">exit()</a></i>,
<i><a href="../xsh/fork.html">fork()</a></i>,
<i><a href="../xsh/pipe.html">pipe()</a></i>,
<i><a href="../xsh/signal.html">signal()</a></i>,
<i><a href="../xsh/system.html">system()</a></i>,
<i><a href="../xsh/ulimit.html">ulimit()</a></i>,
<i><a href="../xsh/umask.html">umask()</a></i>,
<i><a href="../xsh/wait.html">wait()</a></i>.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>
